<?php
class BackupBSN extends GenericBSN {

	function __construct() {
		$this->dao = null;		
	}

	public function fazerBackup() {
		try {
			$mysql_dump	= '"c:\\program files\\mysql\\mysql server 5.5\\bin\\mysqldump.exe"';
			$dump_opt	= "--user=root --password= sape";
			$arq_tmp	= "d:\dump.sql";
			
			$ftp_server = "";
			$ftp_user 	= "";
			$ftp_pass	= "";
			$rmt_file	= "sape_$data.sql";
			$mode		= "FTP_ASCII";
			$data 		= date_format(new DateTime(), "Ymdhis");
			
			exec("$mysql_dump $dump_opt > $arq_tmp");
			
			if ($ftp_server != "") {
				$con	= ftp_connect($ftp_server);
				if (@ftp_login($con, $ftp_user, $ftp_pass)) {
					ftp_put($con, $rmt_file, $arq_tmp, $mode);
					ftp_close($con);
				} else {
					throw new Exception("Falha ao conectar no servidor FTP!");
				}
			}

			$this->Result = "OK";
			$this->Message = "Backup realizado com sucesso!";
		} catch (Exception $e) {
			$this->Result = "ERROR";
			$this->Message = "Erro ao fazer backup dos dados: " . $e->getMessage();
		}
	}
}
?>